1 #include<fstream>
2 #include<iostream>
3 #include<
string>
4 #include<cstdlib>
5 #include <cstring>
6
7 #include<stdio.h>

8 using
namespace std;
9 class
file{
10 public
:
11     file(){
12         ofstream fout;
13         fout.open(
"anish.txt");
14         fout<<
"anish";
15         fout.close();
16     }
17 };

18 class
earn{
19         
public:
20         
double profit;
21         
void show()
22         {
23         ifstream x(
"ooo.txt");
24         
if(!x)
25         cout<<
"PROFIT = 0 ";
26         
else{
27         x>>profit;
28         cout<<
"\nTOTAL STARTING PROFIT: "<<profit<<endl;
29         x.close();
30         }
31         
32         }
33
34 };

35 class
product:public virtual earn{
36 public
:
37            
int quan;
38            
char name[20];
39            
char id[20];
40            
double percost;
41            
double persell;
42            
double cost;
43            
double sell;
44            
void cal()
45            {
46             cost=percost*quan;
47             sell=persell*quan;
48             profit=profit +(sell-cost)*
365;
49             }
50            
void file();
51            
void get();
52
53 };

54 void
product::get()
55 {
56  
int s;
57 cout<<
"\nnumber of products produced?\n";
58 cin>>s;

59 for
(int i=0;i<s;i++)
60 {
61   cout<<
"\ninput product name: \n";
62   cin>>name;
63   cout<<
"\ninput product id: \n";
64   cin>>id;
65   cout<<
"\ninput cost price of product: \n";
66   cin>>percost;
67   cout<<
"\ninput selling price of product: \n";
68   cin>>persell;
69   cout<<
"\ntotal product quantity: \n";
70   cin>>quan;
71     cal();
72     file();
73   }
74  
75 }

76 void
product::file()
77 {

78 char
file[20];
79 strcpy(file,id);
80 strcat(file,
".txt");
81 ofstream f(file);
82 f<<
"\nproduct name: "<<name<< "\nproduct id: "<<id<<"\ncost price of product: " <<percost<<"\nselling price of product: "<<persell<<"\nquantity: "<<quan<<"\n total cost: "<<cost<<"\nsell: "<<sell;
83 f.close();
84 }

85
86 class
staff:public virtual earn{
87          
protected:
88          
double salary;
89          
char post[12];
90          
char empid[10];
91          
int postquan;
92          
void cal()
93          {
94          profit=(profit-salary*postquan)*
12;
95          }
96          
void getstaff();
97          
void file();
98 };

99 void
staff::getstaff()
100 {
101   cout<<
"\ninput salary: \n";
102   cin>>salary;
103   cout<<
"\ninput number of employees: \n";
104   cin>>postquan;
105   
for(int i=0;i<postquan;i++)
106   {
107     cout<<
"input employee name\n";
108     cin>>post;
109   cout<<
"\ninput employee ID\n";
110   cin>>empid;
111   cal();
112   file();
113 }
114 }
115  
void staff::file()
116 {
char file[20];
117 strcpy(file,empid);
118 strcat(file,
".txt");
119 ofstream f(file);
120 f<<
"\nnumber of working employees: "<<postquan<< "\nemployee salary: "<<salary<< "\nemployee name :"<<post<<"\nemployee id: "<<empid;
121 f.close();
122 }

123
124 class
amount:public staff, public product
125 {
126
127  
public:
128     
void add();
129     
void update_item();
130     
void update_emp();
131
132 };

133 void
amount::add()
134 {
135     
int ch;
136     
char name[20];
137     
while(1)
138     {
139         cout<<
"1.)Input for product\n2.)Input for employee\n3.)Exit\n";
140         cout<<
"Enter choice\n";
141         cin>>ch;
142         
if(ch==1){
143                 
get();
144                 ofstream x(
"ooo.txt");
145                 x<<profit;
146                 x.close();
147             }
148             
else if(ch==2){
149                 getstaff();
150                 ofstream x(
"ooo.txt");
151                 x<<profit;
152                 x.close();
153                 }
154             
else if(ch==3)
155                 
break;
156             
else
157                 cout<<
"Invaid Option. Please re-enter\n";
158             }
159         }
160
161  
162     
void amount::update_item()
163     {
164     
char id[20];
165     
char pid[20];
166     
char c;
167     cout<<
"\nINPUT product ID to modify\n";
168     cin>>id;
169     
char file[20];
170     
char file2[20];
171     strcpy(file,id);
172     strcat(file,
".txt");
173     fstream fout(file, ios::
in|ios::out);
174     
if(!fout)
175     {
176         cout<<
"file couldn't be opened. product ID not found. \n";
177     }
178     
else {
179     cout<<
"file found! \n";
180     cout<<
"\nupdate product name: \n";
181     cin>>name;
182     cout<<
"\nupdate percost of product: \n";
183     cin>>percost;
184     cout<<
"\nupdate persell of product: \n";
185     cin>>persell;
186     cout<<
"\nupdate total product quantity: \n";
187     cin>>quan;
188     cost=percost*quan;
189     sell=persell*quan;
190     profit=profit +(sell-cost)*
365;
191     fout<<
"\nproduct name: "<<name<< "\nproduct id: "<<id<<"\npercost ofproduct: " <<percost<<"\npersell of product: "<<persell<<"\nquantity: "<<quan<<"\n total cost: "<<cost<<"\nsell: "<<sell;
192     fout.close();
193 }
194 }
195    
void amount::update_emp()
196     {
197     
char id[20];
198     
char c;
199     cout<<
"\nINPUT employee ID to modify: ";
200     cin>>id;
201     
char file[20];
202     strcpy(file,id);
203     strcat(file,
".txt");
204     fstream fout(file, ios::
in|ios::out);
205      
if(!fout)
206     {
207         cout<<
"file couldn't be opened. product ID not found. \n";
208     }
209     cout<<
"modify employee name: \n";
210     cin>>post;
211     fout<<
"\nnumber of working employees: "<<postquan<< "\nemployee salary: "<<salary<< "\nemployee name :"<<post<<"\nemployee id: "<<empid;
212     fout.close();
213 }

214
215 void
admin()
216 {
217   
while(1)
218   {
219     cout<<
"\n\t\t\t==============================\n";
220     cout<<
"\n\t\t\t WELCOME TO THE SHOP \n";
221     cout<<
"\n\t\t\t==============================\n\n";
222     cout<<
"\n\t\t\t* * * * * * * * * * * * * * * *\n";
223     cout<<
"\n\t\t\t1. Add Entries\n\n\t\t\t2. Show profit\n\n\t\t\t3. Search Product Details\n\n\t\t\t4. Search Employee Details\n\n\t\t\t5. Modify Product Details\n\n\t\t\t6. Modify Employee Details\n\n\t\t\t7. Exit\n";
224   cout<<
"\n\n\t\t\tSelect your choice\n";
225   
int u;
226   cin>>u;

227 if
(u==1)
228   {
229   amount a;
230   a.show();
231   a.
add();
232 }
233   
else if(u==2)
234   {
235   amount d;
236   d.show();
237 }
238   
else if(u==3)
239   {
240    
char id[20];
241    
char c;
242     cout<<
"\nINPUT ID to search\n";
243     cin>>id;
244     
char file[20];
245     strcpy(file,id);
246     strcat(file,
".txt");
247     ifstream x(file);
248     
if(!x)
249     {
250         cout<<
"file couldn't be opened. product ID not found. \n";
251     }
252     
while(x)
253     {x.
get(c);
254      cout<<c;
255     }
256     
257
258     x.close();
259 }
260    
else if(u==4)
261    {
262     
char eid[20];
263     
char d;
264     cout<<
"\nINPUT employee ID to search\n";
265     cin>>eid;
266     
char file[20];
267     strcpy(file,eid);
268     strcat(file,
".txt");
269     ifstream y(file);
270      
if(!y)
271     {
272         cout<<
"file couldn't be opened. employee ID not found. \n";
273     }
274     
while(y)
275     {
276     y.
get(d);
277     cout<<d;
278    }
279  
280    y.close();
281 }

282 else
if(u==5)
283 {
284     amount u;
285     u.update_item();
286 }
287  
else if(u==6)
288  {
289     amount v;
290     v.update_emp();
291  }
292   
else if(u==7)
293   {
294   
break;
295 }
296   
else cout<<"Invalid option. Please select one of the available options\n";
297  }
298
299 }

300
301 int
main(){
302     
int ch;
303     
char username[20];
304     
char password[20];
305     
char pwd[20];
306     
while(1){
307         cout<<
"\n \t\t\t=========================\n";
308         cout<<
"\n\t\t\tWELCOME TO MY SHOP \n";
309         cout<<
"\n \t\t\t=========================\n\n";
310         cout<<
"\n \t\t\t* * * * * * * * * * * * ";
311         cout<<
"\n\t\t\t 1. ENTER SYSTEM";
312         cout<<
"\n\t\t\t 2. EXIT";
313         cout<<
"\n\t\t\t* * * * * * * * * * * *\n";
314         cout<<
"\n\t\t\t Enter Your choice: ";
315         cin>>ch;
316         
switch(ch){
317             
case 1:
318                 admin();
319                 
break;
320             
case 2:
321                 exit(
0);
322                 
break;
323             
default:
324                 cout<<
"Enter valid choice\n";
325                 
break;
326         }
327     }
328     
return 0;
329 }


Gõ tìm kiếm nhanh...